﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace Sixeyed.Guidance.CodeGeneration.ValueProviders.Helpers
{
    /// <summary>
    /// Helper class for retrieving recipe argument values
    /// </summary>
    public static class ValueProviderHelper
    {
        /// <summary>
        /// Returns the value of an optional recipe argument
        /// </summary>
        /// <param name="attributes">Argument dictionary</param>
        /// <param name="argumentName">Argument name</param>
        /// <returns>Argument value, or null if argument not present</returns>
        public static string GetOptionalArgumentValue(StringDictionary attributes, string argumentName)
        {
            string value = null;
            if (attributes.ContainsKey(argumentName))
            {
                value = attributes[argumentName];
            }
            return value;
        }

        /// <summary>
        /// Returns the value of a mandatory recipe argument
        /// </summary>
        /// <remarks>
        /// Throws <see cref="System.ArgumentNullException"/> if argument not present
        /// </remarks>
        /// <param name="attributes">Argument dictionary</param>
        /// <param name="argumentName">Argument name</param>
        /// <param name="missingArgumentExceptionMessage">Message to add to exception if argument not present</param>
        /// <returns>Argument value</returns>
        public static string GetMandatoryArgumentValue(StringDictionary attributes, string argumentName, string missingArgumentExceptionMessage)
        {
            if (!attributes.ContainsKey(argumentName))
            {
                throw new ArgumentNullException(argumentName, missingArgumentExceptionMessage);
            }
            return attributes[argumentName];
        }
    }
}
